package com.dst.service.impl;

import com.dst.dao.StudentMapper;
import com.dst.eneity.Student;
import com.dst.service.StudentService;
import com.dst.utils.MybatisUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
    @Override
    public PageInfo<Student> selectAll(int curPage,int pageSize) {

        PageHelper.startPage(curPage,pageSize);
        List<Student> students = mapper.selectAll();
        PageInfo<Student> pageInfo=new PageInfo<>(students);
        return pageInfo;
    }
    @Override
    public void insertService(Student student) {
        mapper.insert(student);
        sqlSession.commit();
    }

    @Override
    public void update(Student student) {
        mapper.update(student);
        sqlSession.commit();
    }

    @Override
    public Student selectById(int id) {
        Student student = mapper.selectById(id);
        return student;
    }

    @Override
    public void delete(int id) {
        mapper.delete(id);
        sqlSession.commit();
    }

    @Override
    public void batchdelete(int[] ids) {
        mapper.batchDelete(ids);
        sqlSession.commit();
    }
}
